
local skill = fk.CreateSkill {
  name = "lvshi__aoran",
}

Fk:loadTranslationTable{
  ["lvshi__aoran"] = "翱然",
  [":lvshi__aoran"] = "当你获得或失去一次牌后，你可令此回合造成的下一次伤害值为2或0，期间你不能再发动此技能。",
  ["lvshi__aoran1"] = "下一次伤害为2",
  ["lvshi__aoran2"] = "下一次伤害为0",
  ["#lvshi__aoran"] = "%from 的 %arg 被触发，此伤害改为 %arg2 点",
  ["@@lvshi__aoran1-turn"] = "翱然 伤害2",
  ["@@lvshi__aoran2-turn"] = "翱然 伤害0",

  ["$lvshi__aoran1"] = "读兵书千卷，今到用时，可左右施为。",
  ["$lvshi__aoran2"] = "我观夏侯渊中调虎离山之计，可击矣。",
}

skill:addEffect(fk.AfterCardsMove, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skill.name) or player:getMark("@@lvshi__aoran1-turn") > 0 or player:getMark("@@lvshi__aoran2-turn") > 0 then return end
    for _, move in ipairs(data) do
      if move.from == player then
        for _, info in ipairs(move.moveInfo) do
          return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
        end
      elseif move.to == player then
        return move.toArea == Card.PlayerHand
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, {choices = {"lvshi__aoran1", "lvshi__aoran2"}, skill_name = skill.name})
    room:addPlayerMark(player, "@@"..choice.."-turn")
    room:setBanner("lvshi__aoran", choice)
  end,
})

skill:addEffect(fk.DamageCaused, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skill.name, true, true) and player.room:getBanner("lvshi__aoran") and player.room:getBanner("lvshi__aoran") ~= ""
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local banner = room:getBanner("lvshi__aoran")
    room:setBanner("lvshi__aoran", "")
    room:setPlayerMark(player, "@@"..banner.."-turn", 0)
    local n = 2
    if banner == "lvshi__aoran2" then n = 0 end
    room:sendLog{
      type = "#lvshi__aoran",
      from = player.id,
      arg = skill.name,
      arg2 = n,
      toast = true
    }
    if banner == "lvshi__aoran1" then   
      local n = 2 - data.damage
      data:changeDamage(n)
    elseif banner == "lvshi__aoran2" then
      data:changeDamage(-data.damage)
    end
  end,
})

skill:addEffect(fk.TurnEnd, {
  can_refresh = function(self, event, target, player, data)
    return player.room:getBanner("lvshi__aoran")
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setBanner("lvshi__aoran", "")
  end,
})

return skill